<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState">
        <a-form-item name="stdate" label="有效期" class="ml-3 mr-3">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="ck" label="选择仓库" class="ml-4 w-64">
          <SelectWarehouse v-model:value="formState.ck" multiple />
        </a-form-item>

        <a-form-item name="zjm" class="ml-2 w-64">
          <a-input v-model:value="formState.zjm" placeholder="物品编号/物品名称/助记码" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <a-space class="flex justify-end mb-3">
        <BaseExport type="物资" name="效期查询" code="000167" :search-params="formState">导出</BaseExport>
      </a-space>
      <BaseTable :loading="loading" column-code="000167" :data-source="tableData" bordered fill :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'no'">
            <div>{{ index + 1 }}</div>
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record.mc, gg: record.gg, cj: record.cj }" />
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import SelectWarehouse from '@/components/SelectWarehouse'

const formRef = ref(null)
const formState = ref({
  zjm: '',
  ck: [],
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const { loading, tableData, getData, pagination } = useTable({
  url: '/materials/psiform/getValidityDateList',
  immediate: true,
  params: formState.value
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
